package com.Endurancer.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Endurancer.common.annotation.Log;
import com.Endurancer.common.core.controller.BaseController;
import com.Endurancer.common.core.domain.AjaxResult;
import com.Endurancer.common.enums.BusinessType;
import com.Endurancer.manager.domain.BlogRelations;
import com.Endurancer.manager.service.IBlogRelationsService;
import com.Endurancer.common.utils.poi.ExcelUtil;
import com.Endurancer.common.core.page.TableDataInfo;

/**
 * 博客文章与标签关联Controller
 * 
 * @author Endurancer
 * @date 2025-02-02
 */
@RestController
@RequestMapping("/manager/relations")
public class BlogRelationsController extends BaseController
{
    @Autowired
    private IBlogRelationsService blogRelationsService;

    /**
     * 查询博客文章与标签关联列表
     */
    @PreAuthorize("@ss.hasPermi('manager:relations:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogRelations blogRelations)
    {
        startPage();
        List<BlogRelations> list = blogRelationsService.selectBlogRelationsList(blogRelations);
        return getDataTable(list);
    }

    /**
     * 导出博客文章与标签关联列表
     */
    @PreAuthorize("@ss.hasPermi('manager:relations:export')")
    @Log(title = "博客文章与标签关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogRelations blogRelations)
    {
        List<BlogRelations> list = blogRelationsService.selectBlogRelationsList(blogRelations);
        ExcelUtil<BlogRelations> util = new ExcelUtil<BlogRelations>(BlogRelations.class);
        util.exportExcel(response, list, "博客文章与标签关联数据");
    }

    /**
     * 获取博客文章与标签关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:relations:query')")
    @GetMapping(value = "/{relationId}")
    public AjaxResult getInfo(@PathVariable("relationId") Long relationId)
    {
        return success(blogRelationsService.selectBlogRelationsByRelationId(relationId));
    }

    /**
     * 新增博客文章与标签关联
     */
    @PreAuthorize("@ss.hasPermi('manager:relations:add')")
    @Log(title = "博客文章与标签关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogRelations blogRelations)
    {
        return toAjax(blogRelationsService.insertBlogRelations(blogRelations));
    }

    /**
     * 修改博客文章与标签关联
     */
    @PreAuthorize("@ss.hasPermi('manager:relations:edit')")
    @Log(title = "博客文章与标签关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogRelations blogRelations)
    {
        return toAjax(blogRelationsService.updateBlogRelations(blogRelations));
    }

    /**
     * 删除博客文章与标签关联
     */
    @PreAuthorize("@ss.hasPermi('manager:relations:remove')")
    @Log(title = "博客文章与标签关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{relationIds}")
    public AjaxResult remove(@PathVariable Long[] relationIds)
    {
        return toAjax(blogRelationsService.deleteBlogRelationsByRelationIds(relationIds));
    }
}
